<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="../include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);
%>
<html>
  <head>
    <title>资源发现</title>
     <%@ include file="../include/common.jsp"%>
     <%@ include file="../include/jbox.jsp"%>
	 <%@ include file="../include/table.jsp"%>
	  <style type="text/css">
	  	.dataTables_info{
	  		width:500px;
	  	}
	  </style>
	  <script type="text/javascript" src="${pageContext.request.contextPath}/js/tree/jquery.ztree.all-3.1.min.js"></script>
     	<script type=text/javascript>
     	function doFind()
		{
			var url ="iframe:jsp/resource/res-find-progress.jsp?id=${id}&t="+new Date().getMilliseconds();
		
			var opt = { title: "资源发现过程",width:450,height:300,buttons: {}};
			getTopWin(window).openjBox(url,opt,'show-find-progress',window);
		}

		refreshTable = function ()
		{	
			var oTable =$('#findList').dataTable();
			oTable.fnClearTable();
		}
		function confirmIt(){
			var oTable =$('#findList').dataTable();
			var nodesCount = oTable.fnGetNodes().length;
			if(nodesCount<1){
				getTopWin(window).getMessageBox().alert("无可确认资源!","提示");
				return ;
			}
		
			getTopWin(window).getMessageBox().tip('批量确认资源中,请稍候...', 'loading');
			setTimeout("doConfirmIt()",500);
		}
		function doConfirmIt(){
			$.ajax({
				type:'post',
				url:'res-find!doFindRes.action?id=${id}',
				global:false,
				async:false,
				cache:false,
				dataType:'text',
				success:function(data,textStatus){
						getTopWin(window).getMessageBox().tip('批量确认资源变更成功。', 'success',{timeout: 1000});
						var tree = window.parent.getResTree();
						var nodes = tree.getSelectedNodes();
						if ( nodes.length>0) {
							if(!nodes[0].isParent){
								nodes[0].isParent =true;
								tree.updateNode(nodes[0]);
							}
							tree.reAsyncChildNodes(nodes[0], "refresh");
						}
						var oTable =$('#findList').dataTable();
						oTable.fnClearTable();
						displayfindResultNumber(oTable);
					}
				});
		}
		
		//显示发现结果数
		function displayfindResultNumber(oTable){
			var nodes = oTable.fnGetNodes();
 					var addCount = 0;
					var updCount = 0;
					var delCount = 0;
					var cantChange= 0 ;
					$.each(nodes,function(index,ob){
						var oData = oTable.fnGetData(ob);
						var chgType = oData.chgType;
						if(chgType==1){
							addCount++;
						}else if(chgType==2){
							delCount++;
						}else if(chgType==3){
							updCount++;
						}else{
							cantChange ++;
						}
					});
					
					var toolbar =$("div[class='toolbar']");
					var label= toolbar.children('label');
					if(label.length>0){
						label.remove();
					}
					
					toolbar.append("<label style='position:absolute;right:5%;'>共找到<label style='font-weight:bold;'>"+nodes.length+"</label>条记录,无变更<label style='font-weight:bold;color:#0000E3;'>"+cantChange+"</label>条,新增<label style='font-weight:bold;color:#FF0000;'>"+addCount+"</label>条,修改<label style='font-weight:bold;color:#0066CC;'>"+updCount+"</label>条,删除<label style='color:#DCB5FF;font-weight:bold;'>"+delCount+"</label>条</label>");
		}
		
		function initData(){
			var oTable=	$('#findList').dataTable({
				"bProcessing": false, 
				"bServerSide": true,
				"sServerMethod": 'POST',
				"sAjaxSource":'res-find!list.action?id=${id}',
				"bPaginate": false,
				"bSort": false,
				"bFilter":false,
				"bJQueryUI":false,
				"aoColumns":[
					{"mDataProp": "resTypeName"},
					{"mDataProp": "resname"},
					{"mDataProp": "chgStatus"},
					{"mDataProp": "chgContent","fnCreatedCell":function(nTd, sData, oData, iRow, iCol){
						
					}},
					{"mDataProp": "chgType","bVisible":false}
				], 
				"oLanguage": { 
				 	"sZeroRecords": "没有找到记录",
					"sInfoEmpty": "没有找到记录",
					"sInfo": "共找到 _TOTAL_ 条记录"
				},
				"fnInitComplete":function(oSettings){
					displayfindResultNumber(oTable);
				},
				"fnInfoCallback":function( oSettings, iStart, iEnd, iMax, iTotal, sPre ){
					
				}
			});
			
		}
		
		$(document).ready(function(){
 			var findFlag = '${isFindRes}';
			if(findFlag=='false'){
				$("findDiv").hide();
				$('body').html('&nbsp;').css('text-align','center').css('height','500px').css('background-image',"url('${pageContext.request.contextPath}/style/default/images/no-resFind.jpg')");
			}else{
				initData();
			}
		});
     </script>
  </head>
  <body>
   <div id="findDiv" >
	<h2 class="title-h2"><span><img src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif"/></span>资源发现结果列表</h2>
	<div style="width:100%;">
		<div class = "toolbar" style="display:${hasEditResPrivilege?'block':'none'};">
			<a href="#" onclick="doFind();"  class="page_find" id="page_find" >进行发现</a>
			<span class="page_s" >&nbsp;</span>
			<a href="#" onclick="confirmIt();"  class="page_save" id="page_save" >确认</a>
		</div>
		<table id="findList" width="100%" cellpadding="0" cellspacing="0" border="0" class="display">
			<thead>
				<tr>
					<th width="10%">资源类型</th>
					<th width="10%">资源名称</th>
					<th width="10%">变更状态</th>
					<th width="70%">变更内容</th>
		
				</tr>
			</thead>
		</table>
	</div>
   </div>
  </body>
</html>
